package com.whmnx.chitchat.adapter.holder;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;


import com.tencent.qcloud.tim.uikit.utils.DateTimeUtil;
import com.whmnx.chitchat.R;
import com.whmnx.chitchat.bean.ChatDetailsBean;
import com.whmnx.chitchat.utils.UItils;

import java.text.ParseException;
import java.util.Date;

/**
 * @author Administrator
 */
public abstract class MessageEmptyHolder2 extends MessageBaseHolder2 {

    public TextView chatTimeText;
    public FrameLayout msgContentFrame;

    public MessageEmptyHolder2(View itemView) {
        super(itemView);
        rootView = itemView;

        chatTimeText = itemView.findViewById(R.id.chat_time_tv);
        msgContentFrame = itemView.findViewById(R.id.msg_content_fl);
        initVariableLayout();
    }

    public abstract int getVariableLayout();

    private void setVariableLayout(int resId) {
        if (msgContentFrame.getChildCount() == 0) {
            View.inflate(rootView.getContext(), resId, msgContentFrame);
        }
        initVariableViews();
    }

    private void initVariableLayout() {
        if (getVariableLayout() != 0) {
            setVariableLayout(getVariableLayout());
        }
    }

    public abstract void initVariableViews();

    @Override
    public void layoutViews(final ChatDetailsBean msg, final int position) {
        //// 时间线设置
        if (properties.getChatTimeBubble() != null) {
            chatTimeText.setBackground(properties.getChatTimeBubble());
        }
        if (properties.getChatTimeFontColor() != 0) {
            chatTimeText.setTextColor(properties.getChatTimeFontColor());
        }
        if (properties.getChatTimeFontSize() != 0) {
            chatTimeText.setTextSize(properties.getChatTimeFontSize());
        }
        long t = UItils.dateToStamp(msg.getCreateTime());
        if (position > 1) {
            ChatDetailsBean last = mAdapter.getItem(position - 1);
            if (last != null) {

                   long t1 = UItils.dateToStamp(last.getCreateTime());

                if (t - t1 >= 5 * 60) {
                    chatTimeText.setVisibility(View.VISIBLE);
                    chatTimeText.setText(DateTimeUtil.getTimeFormatText(new Date(t*1000)));
                } else {
                    chatTimeText.setVisibility(View.GONE);
                }
            }
        } else {
            chatTimeText.setVisibility(View.VISIBLE);
            chatTimeText.setText(DateTimeUtil.getTimeFormatText(new Date(t*1000)));
        }
    }
}
